<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        window.onload = function(){
            var btn = document.getElementById("btn");
            btn.onclick = function(){
                var start = Date.now();
                // 记录开始的时间
                setTimeout(function(){
                    console.log("输出所用时间:"+(Date.now()-start));
                },2000)
                // 五秒后定时器输出文字
            }
        }
    </script>
</head>
<body>
    <button id="btn">按钮</button>
</body>
</html>